package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.Aspect.UserPer;
import com.mc.read.adminapi.manager.StatisticsManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author liuhao
 * @date 2019/6/17 18:38
 */
@Service
@Slf4j
public class StatisticsService {
    @Autowired
    StatisticsManager statisticsManager;
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 下载量统计 statisticsForDownload
     **/
    @UserPer(permission = "statistics:download:download")
    @UserLog(operateName = "下载量统计", type = 4)
   public BaseRespose statisticsForDownload(@RequestBody BaseRequest baseRequest){
        log.info("下载量统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.statisticsForDownload(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("下载量统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("下载量统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户注册统计 staUserReg
     **/
    @UserPer(permission = "statistics:userreg:userreg")
    @UserLog(operateName = "用户注册统计", type = 4)
    public BaseRespose staUserReg(@RequestBody BaseRequest baseRequest){
        log.info("用户注册统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserReg(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户注册统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户注册统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 活跃用户统计 staActiveUser
     **/
    @UserPer(permission = "statistics:activeuser:activeuser")
    @UserLog(operateName = "活跃用户统计", type = 4)
    public BaseRespose staActiveUser(@RequestBody BaseRequest baseRequest){
        log.info("活跃用户统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staActiveUser(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("活跃用户统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("活跃用户统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 阅读时间段统计 staReadTime
     **/
    @UserPer(permission = "statistics:readtime:readtime")
    @UserLog(operateName = "阅读时间段统计", type = 4)
    public BaseRespose staReadTime(@RequestBody BaseRequest baseRequest){
        log.info("阅读时间段统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staReadTime(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("阅读时间段统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("阅读时间段统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 功能点击次数统计 staFunctionClick
     **/
    @UserPer(permission = "statistics:functionClick:functionClick")
    @UserLog(operateName = "功能点击次数统计", type = 4)
    public BaseRespose staFunctionClick(@RequestBody BaseRequest baseRequest){
        log.info("功能点击次数统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staFunctionClick(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("功能点击次数统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("功能点击次数统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }


    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 小说类型累计阅读人数 staBookTypeReadSum
     **/
    @UserPer(permission = "statistics:staBookTypeReadSum:staBookTypeReadSum")
    @UserLog(operateName = "小说类型累计阅读人数", type = 4)
    public BaseRespose staBookTypeReadSum(@RequestBody BaseRequest baseRequest) {
        log.info("小说类型累计阅读人数,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staBookTypeReadSum(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("小说类型累计阅读人数 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("小说类型累计阅读人数 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 不活跃用户统计 staNotActiveUser
     **/
    @UserPer(permission = "statistics:staNotActiveUser:staNotActiveUser")
    @UserLog(operateName = "不活跃用户统计", type = 4)
    public BaseRespose staNotActiveUser(@RequestBody BaseRequest baseRequest){
        log.info("不活跃用户统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staNotActiveUser(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("不活跃用户统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("不活跃用户统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 热门小说统计 selectHotBook
     **/
    @UserPer(permission = "statistics:selectHotBook:selectHotBook")
    @UserLog(operateName = "热门小说统计", type = 4)
    public BaseRespose selectHotBook(@RequestBody BaseRequest baseRequest){
        log.info("热门小说统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.selectHotBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("热门小说统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("热门小说统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }


    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 根据收入查询喜欢类型 staBookTypeByIncome
     **/
    @UserPer(permission = "statistics:staBookTypeByIncome:staBookTypeByIncome")
    @UserLog(operateName = "根据收入查询喜欢类型", type = 4)
    public BaseRespose staBookTypeByIncome(@RequestBody BaseRequest baseRequest){
        log.info("根据收入查询喜欢类型,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staBookTypeByIncome(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("根据收入查询喜欢类型 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据收入查询喜欢类型 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户男女比例统计 staUserSex
     **/
    @UserPer(permission = "statistics:staUserSex:staUserSex")
    @UserLog(operateName = "用户男女比例统计", type = 4)
    public  BaseRespose staUserSex(@RequestBody BaseRequest baseRequest){
        log.info("用户男女比例统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserSex(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户男女比例统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户男女比例统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户地区分布 staUserRegion
     **/
    @UserPer(permission = "statistics:staUserRegion:staUserRegion")
    @UserLog(operateName = "用户地区分布", type = 4)
    public BaseRespose staUserRegion(@RequestBody BaseRequest baseRequest){
        log.info("用户地区分布,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserRegion(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户地区分布 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户地区分布 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户年龄分布 staUserAge
     **/
    @UserPer(permission = "statistics:staUserAge:staUserAge")
    @UserLog(operateName = "用户年龄分布", type = 4)
    public BaseRespose staUserAge(@RequestBody BaseRequest baseRequest){
        log.info("用户年龄分布,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserAge(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户年龄分布 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户年龄分布 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户书籍类型分布 staUserBookBype
     **/
    @UserPer(permission = "statistics:staUserBookBype:staUserBookBype")
    @UserLog(operateName = "用户书籍类型分布", type = 4)
    public BaseRespose staUserBookBype(@RequestBody BaseRequest baseRequest){
        log.info("用户书籍类型分布,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserBookBype(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户书籍类型分布 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户书籍类型分布 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户阅读时长统计 staUserReadTime
     **/
    @UserPer(permission = "statistics:staUserReadTime:staUserReadTime")
    @UserLog(operateName = "用户阅读时长统计", type = 4)
    @RequestMapping(value = "/statistics/staUserReadTime", method = RequestMethod.POST)
    public BaseRespose staUserReadTime(@RequestBody BaseRequest baseRequest){
        log.info("用户阅读时长统计,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserReadTime(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户阅读时长统计 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户阅读时长统计 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户收藏排行 staUserCollection
     **/
    @UserPer(permission = "statistics:staUserCollection:staUserCollection")
    @UserLog(operateName = "用户收藏排行", type = 4)
    public BaseRespose staUserCollection(@RequestBody BaseRequest baseRequest){
        log.info("用户收藏排行,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserCollection(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户收藏排行 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户收藏排行 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 某本小说的男女比例 staUserSexByBook
     **/
    @UserPer(permission = "statistics:staUserSexByBook:staUserSexByBook")
    @UserLog(operateName = "某本小说的男女比例", type = 4)
    public BaseRespose staUserSexByBook(@RequestBody BaseRequest baseRequest){
        log.info("某本小说的男女比例,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserSexByBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("某本小说的男女比例 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("某本小说的男女比例 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 某本小说的地区分布 staUserRegionByBook
     **/
    @UserPer(permission = "statistics:staUserRegionByBook:staUserRegionByBook")
    @UserLog(operateName = "某本小说的地区分布", type = 4)
    public BaseRespose staUserRegionByBook(@RequestBody BaseRequest baseRequest){
        log.info("某本小说的地区分布,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserRegionByBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("某本小说的地区分布 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("某本小说的地区分布 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 某本小说的收入分布 staUserIncomeByBook
     **/
    @UserPer(permission = "statistics:staUserIncomeByBook:staUserIncomeByBook")
    @UserLog(operateName = "某本小说的收入分布", type = 4)
    public BaseRespose staUserIncomeByBook(@RequestBody BaseRequest baseRequest){
        log.info("某本小说的收入分布,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = statisticsManager.staUserIncomeByBook(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("某本小说的收入分布 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("某本小说的收入分布 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

}
